package com.wx.service.impl;

import com.wx.constants.Constants;
import com.wx.entity.SysArticle;
import com.wx.exception.BusinessException;
import com.wx.mapper.SysArticleMapper;
import com.wx.service.SysArticleService;
import com.wx.utils.SnowFlakeUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>Title:	  weixin-go-with-you <br/> </p>
 * <p>Description TODO <br/> </p>
 * <p>Company:    医百科技有限公司  <br/> </p>
 *
 * @Author <a href="yangwensheng@100doc.com.cn"/>杨文生</a>  <br/>
 * @Date 2021/4/5 21:22
 */
@Service
public class SysArticleServiceImpl extends BaseServiceImpl<SysArticle> implements SysArticleService {

    @Resource
    private SysArticleMapper sysArticleMapper;

    @Override
    public SysArticle selectByType(Integer type) {
        return sysArticleMapper.selectByType(type);
    }

    @Override
    public int saveArticle(SysArticle sysArticle) {
        sysArticle.setId(SnowFlakeUtil.getStringId());
        return sysArticleMapper.insertSelective(sysArticle);
    }

    @Override
    public int deleteById(String id, String userId, String realName) {
        SysArticle sysArticle = sysArticleMapper.selectByPrimaryKey(id);
        if(sysArticle == null){
            throw new BusinessException("参数不合法");
        }
        sysArticle.setDelFlag(Constants.DELETE_YES);
        sysArticle.setUpdateBy(userId);
        sysArticle.setUpdater(realName);
        sysArticle.setUpdateDate(new Date());
        return sysArticleMapper.updateByPrimaryKeySelective(sysArticle);
    }

    @Override
    public List<SysArticle> listPage(SysArticle param) {
        return sysArticleMapper.listPage(param);
    }
}
